Add which-key-max-display-columns
authorJustin Burkett <justin@burkett.cc>
Tue, 20 Dec 2016 20:56:35 +0000 (15:56 -0500)
committerJustin Burkett <justin@burkett.cc>
Tue, 20 Dec 2016 20:56:35 +0000 (15:56 -0500)
See #157

which-key.el

index 6545026c7f2057c737a78662ad356e7cf5cc3e7d..9a44be9b45886b69faea7b45d818bc70705ecdba 100644 (file)
@@ -256,6 +256,12 @@ and nil. Nil turns the feature off."
   :group 'which-key
   :type 'integer)
 
+(defcustom which-key-max-display-columns nil
+  "The maximum number of columns to display in the which-key
+buffer. nil means don't impose a maximum."
+  :group 'which-key
+  :type 'integer)
+
 (defcustom which-key-side-window-location 'bottom
   "Location of which-key popup when `which-key-popup-type' is side-window.
 Should be one of top, bottom, left or right. You can also specify
@@ -1608,7 +1614,7 @@ Returns a plist that holds the page strings, as well as
 metadata."
   (let ((cols-w-widths (mapcar #'which-key--pad-column
                                (which-key--partition-list avl-lines keys)))
-        (page-width 0) (n-pages 0) (n-keys 0)
+        (page-width 0) (n-pages 0) (n-keys 0) (n-columns 0)
         page-cols pages page-widths keys/page col)
     (if (> (apply #'max (mapcar #'car cols-w-widths)) avl-width)
         ;; give up if no columns fit
@@ -1617,17 +1623,21 @@ metadata."
       (while cols-w-widths
         ;; start new page
         (cl-incf n-pages)
-        (setq col (pop cols-w-widths)
-              page-cols (list (cdr col))
-              page-width (car col)
-              n-keys (length (cdr col)))
+        (setq col (pop cols-w-widths))
+        (setq page-cols (list (cdr col)))
+        (setq page-width (car col))
+        (setq n-keys (length (cdr col)))
+        (setq n-columns 1)
         ;; add additional columns as long as they fit
         (while (and cols-w-widths
+                    (or (null which-key-max-display-columns)
+                        (< n-columns which-key-max-display-columns))
                     (<= (+ (caar cols-w-widths) page-width) avl-width))
           (setq col (pop cols-w-widths))
           (push (cdr col) page-cols)
           (cl-incf page-width (car col))
-          (cl-incf n-keys (length (cdr col))))
+          (cl-incf n-keys (length (cdr col)))
+          (cl-incf n-columns))
         (push (which-key--join-columns page-cols) pages)
         (push n-keys keys/page)
         (push page-width page-widths))